//
//  GuidanceViewController.m
//  LOU
//
//  Created by apple on 15/11/16.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "GuidanceViewController.h"

#import "AppDelegate.h"
#import "HomeViewController.h"
#import "PropertyViewController.h"
#import "ClientViewController.h"
#import "WealthViewController.h"
#import "MineViewController.h"
#import "Size.h"

@interface GuidanceViewController ()<UIApplicationDelegate,UIScrollViewDelegate>{
    CGRect rect;
    BOOL _isLock;
    
}



///@property(nonatomic, strong)UIScrollView *scrollView;
@property(nonatomic, strong)UITabBarController *tab;
//@property(nonatomic,strong)UIPageControl *pageControl;

@end

@implementation GuidanceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIScrollView * scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, WindowHeight)];
    scrollView.tag = 100;
    scrollView.maximumZoomScale = 10;
    scrollView.minimumZoomScale = 0.1;
    scrollView.backgroundColor = [UIColor cyanColor];
    
    //设置滚动范围 当宽度<= frame.size.width,不能左右滚动,只能上下滚动,反之一样
    scrollView.contentSize = CGSizeMake(WindowWidth * 5, WindowHeight);
    scrollView.delegate = self;
    //内容视图的原点相对于scrollView原点的偏移量
    //scrollView.contentOffset = CGPointMake(50, 50);
    
    //内容视图相当于scrollView的边界上下左右内移多少开始显示
    //scrollView.contentInset = UIEdgeInsetsMake(20, 10, 20, 20);
    
    //是否让视图滚动 默认是可以滚动的
    //scrollView.scrollEnabled = NO;
    
    //左右滚动的时候 不能上下滚动 反之一样 默认是NO
    //scrollView.directionalLockEnabled = YES;
    
    //滚到边界时 是否有反弹 默认YES
    //scrollView.bounces = NO;
    
    //滚动条的风格 默认黑色半透明
    //scrollView.indicatorStyle =  UIScrollViewIndicatorStyleBlack;
    
    //是否需要哪个方向的滚动条 默认YES
    scrollView.showsHorizontalScrollIndicator = NO;
    //scrollView.showsVerticalScrollIndicator = NO;
    
    //翻页
    NSArray *array = @[@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg",@"5.jpg"];
    scrollView.pagingEnabled = YES;
    
    
    for (int i = 0; i < array.count; i++) {
        UIImageView * aImageView = [[UIImageView alloc] initWithFrame:CGRectMake(WindowWidth * i, 0, WindowWidth, WindowHeight)];
        aImageView.image = [UIImage imageNamed:array[i]];
        [scrollView addSubview:aImageView];
        [self.view addSubview:scrollView];
        aImageView.userInteractionEnabled = YES;
        if (i == (array.count - 1)) {
            /*  最后一个页面设置一个button */
            UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
            
            //        button.backgroundColor = [UIColor orangeColor];
            button.frame = CGRectMake((WindowWidth-100)/2, (WindowHeight - 50)/2, 200, 50);
           // button.center = CGPointMake(self.view.center.x + 4 * self.view.frame.size.width, 580 / 667.0 * self.view.frame.size.height);
            //        button.tintColor = [UIColor blackColor];
            button.titleLabel.font = [UIFont systemFontOfSize:20];
            [button addTarget:self action:@selector(pressButton1) forControlEvents:(UIControlEventTouchUpInside)];
            [button setTitle:@"点击进入" forState:UIControlStateNormal];
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            button.backgroundColor = [UIColor greenColor];
            [aImageView addSubview:button];
        }
        
    }
    UIPageControl  * pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(10, WindowHeight - 50, WindowWidth - 20, 20)];
    pageControl.numberOfPages = 5;
    pageControl.tag = 200;
    [self.view addSubview:pageControl];
    [pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];

}
- (void)changePage:(UIPageControl*)pageControl
{
    _isLock = YES;
    UIScrollView * scrollView = (UIScrollView*)[self.view viewWithTag:100];
    
    [scrollView setContentOffset:CGPointMake(320 * pageControl.currentPage, 0) animated:YES];
    
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
    if (!_isLock) {
        UIPageControl  * pageControl = (UIPageControl*)[self.view viewWithTag:200];
        pageControl.currentPage = floor(scrollView.contentOffset.x + 160 )/ 320;
        
        
    }
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    _isLock = NO;
    NSLog(@"%s",__FUNCTION__);
}


- (void)pressButton1{
    AppDelegate *appdelegate = [[UIApplication sharedApplication] delegate];
    appdelegate.window.rootViewController = appdelegate.tab;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
